package com.hk.core.data.mongodb.domain;

import com.hk.commons.util.AuditField;
import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedBy;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.domain.Auditable;
import org.springframework.data.mongodb.core.mapping.Field;
import org.springframework.data.mongodb.core.mapping.FieldType;

import java.time.LocalDateTime;
import java.util.Optional;

/**
 * @author kevin
 * @date 2019-7-2 16:59
 */
public class AbstractSnowflakeAuditable extends AbstractSnowflakeIdPersistable implements Auditable<Long, Long,
        LocalDateTime>, AuditField {

    @CreatedBy
    @Field(value = CREATED_BY, targetType = FieldType.INT64, write = Field.Write.NON_NULL)
    private Long createdBy;

    /**
     * 创建时间
     */
    @CreatedDate
    @Field(value = CREATED_DATE, targetType = FieldType.DATE_TIME, write = Field.Write.NON_NULL)
    private LocalDateTime createdDate;

    /**
     * 最后更新用户
     */
    @Field(value = LAST_MODIFIED_BY, targetType = FieldType.INT64)
    @LastModifiedBy
    private Long lastModifiedBy;

    /**
     * 最后更新时间
     */
    @LastModifiedDate
    @Field(value = LAST_MODIFIED_DATE, targetType = FieldType.INT64)
    private LocalDateTime lastModifiedDate;

    @Override
    public Optional<Long> getCreatedBy() {
        return Optional.ofNullable(createdBy);
    }

    @Override
    public void setCreatedBy(Long createdBy) {
        this.createdBy = createdBy;
    }

    @Override
    public Optional<LocalDateTime> getCreatedDate() {
        return Optional.ofNullable(createdDate);
    }

    @Override
    public void setCreatedDate(LocalDateTime creationDate) {
        this.createdDate = creationDate;
    }

    @Override
    public Optional<Long> getLastModifiedBy() {
        return Optional.ofNullable(lastModifiedBy);
    }

    @Override
    public void setLastModifiedBy(Long lastModifiedBy) {
        this.lastModifiedBy = lastModifiedBy;
    }

    @Override
    public Optional<LocalDateTime> getLastModifiedDate() {
        return Optional.ofNullable(lastModifiedDate);
    }

    @Override
    public void setLastModifiedDate(LocalDateTime lastModifiedDate) {
        this.lastModifiedDate = lastModifiedDate;
    }

    @Override
    public boolean equals(Object obj) {
        return super.equals(obj);
    }

    @Override
    public int hashCode() {
        return super.hashCode();
    }
}
